import threading

class PeriodicTask():

    def __init__(self, period=1, callbackfct=[]):
        self.period=period
        self.callbackfct=callbackfct
        self.stop=False
    
    def setPeriod(self,period):
        self.period=period
        
    def setCallbackfct(self, callbackfct):
        self.callbackfct=callbackfct

    def startTimer(self):
        if self.stop==False:
            self.timer=threading.Timer(self.period, self.startTimer)
            self.callbackfct()
            self.timer.start()

    def stopTimer(self):
        self.stop=True
